n = int(input())
a = list(map(int, input().split()))
q = [0] * n
q[0] = -2e-9
# 长度是i 的， 结尾是最小的子序列  的最后一位是q[i]
len = 0
for i in range(n):
    l, r = 0, len
    while l < r:
        mid = l + r >> 1
        if q[mid] < a[i]:
            l = mid
        else:
            r = mid - 1
    len = max(len, r + 1)
    q[r + 1] = a[i]
# q[i] 会被不断更新，后面不断会有更小的数x，q[i] = x
print(len)
